package com.opages.netty.demo.netty.codec;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

import java.nio.charset.Charset;

/**
 * @author daizhong.liu
 * @create 2021-12-15 10:28
 **/
public class ClientHandler extends SimpleChannelInboundHandler<Long> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Long msg) throws Exception {
        System.err.println("接收服务端消息:【"+ctx.channel().remoteAddress()+"】,消息内容:【"+msg+"】");
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.err.println("连接成功，准备发送数据");
//        ctx.writeAndFlush(Unpooled.wrappedBuffer("test,Hello world my heart...".getBytes(CharsetUtil.UTF_8)));
        ctx.writeAndFlush(888L);
    }
}
